import { createNode } from "./createNode"
import { Context, Visitor, Node } from "./node"

/**
 * 清除弹框
 */
export class ClearDialogVisitor implements Visitor {
    visitNode(node: Node, ctx: Context) {
        if (!node.visibleToUser) return;
        if (node.text === `我知道了`) {
            if (node.parent.children.map(node => node.text).includes(`开启青少年模式`)) {
                node.clickOrRect()
            }
        }
        if (node.text === `收到快手的提现红包`) {
            node.parent.prev().click()
        }
        if (node.text === `忽略`) {
            node.clickOrParent()
        }
        if (node.text === `直播已结束`) {
            node.spipeUp()
        }
        if (node.text === '立即关注') {
            back();
        }
        if (node.text === '朋友推荐') {
            back();
        }
        if (node.text === `以后再说`) {
            node.clickOrParent()
        }
        if (node.text === `立即领取`) {
            node.parent.parent.children[1]?.click()
        }
        if (node.text === `去看看`) {
            node.parent.parent.children[1]?.click()
        }
        if (node.text === `关注主播抢红包`) {
            back();
        }
        if (node.text.includes(`本次未中奖`)) {
            back();
        }
        if (node.text === '拒绝') {
            node?.click()
        }
        if (node.text === '退出直播间') {
            node.parent?.click()
        }
        if (node.text === '退出') {
            node.clickOrParent()
        }
        if (node.text === '跳过') {
            node.clickOrParent()
        }
        if (node.text === '支持红队') {
            back();
        }
        if (node.text === '领取并使用') {
            back();
        }
        if (node.text === '关注并领取') {
            back();
        }
        if (node.text === '限时福利，试试手气') {
            back();
        }
        if (node.text === '去填写') {
            back();
        }
        if (node.text === '分享') {
            back();
        }
        if (node.text === '很遗憾，本次任务失败') {
            back();
        }
        if (node.text === '看看大家手气') {
            back()
        }
        if (node.id && node.id.endsWith('action_view')) {
            back();
        }
        // node.text && log(node.text)
        node.children.map(c => c.visit(this, ctx))
    }
}

export function clearDialog() {
    const ctx = new Context();
    const node = createNode()
    new ClearDialogVisitor().visitNode(node, ctx)
}
